/*
 * Vertex.cpp
 *
 *  Created on: 15/09/2009
 *      Author: mario
 */

#include "Vertex.h"

Vertex::Vertex(string id, float x, float y) {
	setX(x);
	setY(y);
	setId(id);
	edgesList = new List();
}

Vertex::~Vertex() {
	//std::cout << "Kill vertex\n";
	delete edgesList;
}

string Vertex::getId() const
 {
	return id;
 }

 void Vertex::setId(string id)
 {
	this->id = id;
 }

 List* Vertex::getEdgesList() const
 {
     return edgesList;
 }

 void Vertex::setEdgesList(List* edgesList)
 {
     this->edgesList = edgesList;
 }

 float Vertex::getX() const
 {
     return x;
 }

 void Vertex::setX(float x)
 {
     this->x = x;
 }

 float Vertex::getY() const
 {
     return y;
 }

 void Vertex::setY(float y)
 {
     this->y = y;
 }

 int Vertex::createEdge(string id, string idFrom, string idTo, float length, float maxVelocity, string wayType, string wayName, int initAddress, int lastAddress)
 {
	 //Cheks for duplicate ID's
	 if (getEdge(id) != NULL) return ID_REPEATED;
	 else {
		 Edge* edge = new Edge(id,idFrom,idTo,length,maxVelocity,wayType,wayName,initAddress,lastAddress);
		 EdgeNode* node = new EdgeNode();
		 if ((edge ==NULL) || (node == NULL)) return MEMORY_ERROR;
		 node->setNodeValue(edge);
		 getEdgesList()->add(node);
		 return 0;	 
	 }
 }
 
 Edge* Vertex::getEdge(string id)
 {
 	for (int i = 0; i < getEdgesList()->getSize(); i++) {
 		EdgeNode* node = (EdgeNode*) getEdgesList()->get(i);
 		Edge* e =  node->getNodeValue();
 		string value = e->getId();
		if (value.compare(id) == 0) {
 			return node->getNodeValue();
 		}
 	}
 	return NULL;
 }
